package Learn;

import java.util.StringJoiner;

//一个接口中没由抽象方法
//标记性接口
//一旦实现了 就可以被克隆 没有就不能

public class User implements Cloneable {
    private int id;//游戏角色
    private String name;
    private String password;//
    private String path;//游戏图片
    private int[] data;//游戏进度


    public User() {
    }

    public User(int id, String name, String password, String path, int[] data) {
        this.id = id;
        this.name = name;
        this.password = password;
        this.path = path;
        this.data = data;
    }

    /**
     * 获取
     *
     * @return id
     */
    public int getId() {
        return id;
    }

    /**
     * 设置
     *
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * 设置
     *
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * 获取
     *
     * @return path
     */
    public String getPath() {
        return path;
    }

    /**
     * 设置
     *
     * @param path
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * 获取
     *
     * @return data
     */
    public int[] getData() {
        return data;
    }

    /**
     * 设置
     *
     * @param data
     */
    public void setData(int[] data) {
        this.data = data;
    }

    public String toString() {
        return "User{id = " + id + ", name = " + name + ", password = " + password + ", path = " + path + ", data = " + arrToString() + "}";
    }

    public String arrToString() {
        StringJoiner sj = new StringJoiner(",", "[", "]");
        for (int i = 0; i < data.length; i++) {
            sj.add(data[i] + " ");
        }
        return sj.toString();

    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //调用父类中的方法
//        return super.clone();

        //深克隆重写
        int []data=this.data;
        int []newData=new int[data.length];

        for (int i = 0; i < data.length; i++) {
            newData[i]=data[i];
        }

        User u=(User)super.clone();
        u.data=newData;
        return u;

    }
}
